package rdp.cmd.vocation;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.*;

import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import rdp.RDPUtil;

public class CMDVocation {

    String[] vocation = new String[]{"石匠","矿工"};
    HashMap<String,Material> material = new HashMap<String,Material>(){{
        put("石匠",Material.STONECUTTER);
        put("矿工",Material.STONE_PICKAXE);
    }};
    HashMap<String,String[]> skill = new HashMap<String,String[]>() {{
        put("石匠", new String[]{"随身切石机", "石器工艺", "收纳强化", "物尽其用"});
        put("矿工", new String[]{"采掘许可证", "挖掘专精", "精准采集", "暴走矿工"});
    }};

    String[] getDesc(String str) {
        Map info = new HashMap() {{
            put("随身切石机",new String[]{
                    "你随身携带着一个小巧的切石机。",
                    "可以随时随地打开切石机界面。"
            });
            put("石器工艺",new String[]{
                    "你学会了如何打磨与保养手中的石制工具，可喜可贺。",
                    "消耗经验强化石制工具，使其变得变加锐利或是耐用。"
            });
            put("收纳强化",new String[]{
                    "你比其他人更懂得如何利用有效的空间来存储这些废料。",
                    "各种石料的堆叠上限提升了。"
            });
            put("物尽其用",new String[]{
                    "石料堆积如山？或许里面会有许多宝贝也说不定！",
                    "消耗大量石头随机抽取矿物。"
            });
            put("采掘许可证",new String[]{
                    "严禁无证采掘者开矿，一经发现与盗掘行为同罪判处。",
                    "你得到了采掘许可证，现在可以挖掘煤炭以外的矿物了。"
            });
            put("挖掘专精",new String[]{
                    "专业的采掘者更加细心，他们比起业余采掘者往往会有更多的收获。",
                    "受时运加成的矿物在你的镐下将会有更多的掉落。"
            });
            put("精准采集",new String[]{
                    "能毫发无损的将眼前的矿物运送回家也是采掘者的本事。",
                    "消耗经验可以使你更精确的采集眼前的方块，当然，慢工出细活。"
            });
            put("暴走矿工",new String[]{
                    "没有人会建议你这么做，除非你真的是个急性子。",
                    "获得急迫，但每一次破坏方块都会扣除生命值。"
            });
        }};

        return (String[]) info.get(str);
    }

    private Map info = new HashMap() {{
        put("职业群", new HashMap() {{
            put("支援系", new HashMap() {{
                put("水平", new String[]{"新手", "能手", "达人", "大师"});
                put("职业", new HashMap() {{
                    put("石匠", new String[]{"随身切石机", "石器工艺", "收纳强化", "物尽其用"});
                    put("矿工", new String[]{"采掘许可证", "挖掘专精", "精准采集", "暴走矿工"});
                    put("渔翁", new String[]{"钓鱼许可证", "钓鱼专精", "收纳强化", "涸泽而渔"});
                    put("庖丁", new String[]{"随身烟熏炉", "配种专精", "屠宰专精", "焚林而猎"});
                    put("耕佣", new String[]{"耕种许可证", "农耕专精", "拔苗助长", "五谷丰登"});
                    put("樵夫", new String[]{"伐木许可证", "木植专精", "制炭工艺", "舍生忘死"});
                    put("药师", new String[]{"随身炼药台", "研磨专精", "收纳强化", "对症下药"});
                    put("学者", new String[]{"附魔许可证", "附魔专精", "祛魔专精", "学无止境"});
                    put("铁匠", new String[]{"随身冶金炉", "锻器工艺", "锻甲工艺", "独具匠心"});
                    put("浪客", new String[]{"随身制图台", "贪生怕死", "视财如命", "就地取材"});
                    put("裁缝", new String[]{"持剪许可证", "皮革工艺", "丝绸工艺", "飞针走线"});
                    put("技工", new String[]{"撬棍许可证", "暂无技能", "暂无技能", "一触即发"});
                }});
            }});
            put("战斗系", new HashMap() {{
                /**
                 * ------------
                 * 探险家 - 脱战速度提升，生命回复
                 * 登山客 - 脱战跳跃提升，高山夜视
                 * 好水者 - 水下呼吸，水下速掘，水下夜视
                 * 拾荒者 - 物品堆叠提升
                 * ----------------------
                 * ======战斗系职业======
                 * 剑客 - 持剑时 攻击提升，副限，铁甲
                 * 斧者 - 持斧时 攻击提升，副限，铁甲
                 * 戟使 - 持戟时 攻击提升，副限，铁甲
                 * 盾卫 - 持盾时 攻击提升，防御提升，副限，铁甲，击退
                 * 拳师 - 空手时 攻击提升，防御提升，副限，皮甲，缴械
                 * 刺客 - 铁武时 攻击提升，防御下降，速度提升，副限，皮甲，破甲
                 * 骑士 - 铁防时 防御提升，攻击下降，无副限，钻甲
                 * 弓手 - 持弓时 攻击提升，防御下降，副限，铁甲，箭堆叠上升
                 * 弩手 - 持弩时 攻击提升，防御下降，副限，铁甲，破甲
                 * ------------
                 * 侦察兵 - 探测技能(范围实体高光标记)
                 * 先驱者 - 集结技能(面向先驱移速增加)
                 * ----------------------
                 */
            }});
        }});

    }};

    public boolean execute(CommandSender sender, String[] args) {
        boolean isAdmin = sender.hasPermission("minecraft");
        boolean isPlayer = sender instanceof Player;
        Player player = isPlayer ? (Player) sender : null;
        Player target = null;

        if (args.length == 1) {
            args = new String[]{"vocation", "menu"};
        }
        if (getCmd(args[1]) == "menu") {
            if (isPlayer) {
                player.openInventory(getMenu());
                return true;
            } else
                args = new String[]{"vocation", "help"};
        }
        if (getCmd(args[1]) == "help") {
            RDPUtil.SEND(sender, getHelp());
            return true;
        }
        switch (getCmd(args[1])) {
            case "list":
                for (Iterator<Score> it = player.getScoreboard().getScores("test").iterator(); it.hasNext(); it.next()) {
                    System.out.println(it.toString());
                    System.out.println(it.next().getScore());
                }
                RDPUtil.SEND(sender, getVocationList(player));
                break;
            case "check":
                break;
            default:
                RDPUtil.SEND(sender, "§4指令不存在。");
        }
        return true;
    }

    private String[] getVocationList(Player player) {
        return new String[]{

        };
    }

    private String getCmd(String str) {
        List<String[]> list = new ArrayList();
        list.add(new String[]{"?", "help"});
        list.add(new String[]{"!", "menu"});
        list.add(new String[]{"l", "list"});
        list.add(new String[]{"c", "check"});

        for (String[] strs : list) {
            if (RDPUtil.CHECK(str, strs))
                return strs[strs.length - 1];
        }
        return null;
    }

    private String[] getHelp() {
        return new String[]{
                "§b/rdp vocation help§f - 获取职业指令组帮助。",
                "§b/rdp vocation menu§f - 打开职业菜单。",
                "§b/rdp vocation list§f - 查看职业列表。",
                "§b/rdp vocation check§f - 查看职业信息。"
        };
    }

    private Inventory getMenu() {
        Inventory inv = Bukkit.createInventory(null, 54, "职业菜单");

        ItemStack blank = new ItemStack(Material.GLASS_PANE);
        ItemMeta blankIM = blank.getItemMeta();
        blankIM.setDisplayName("");
        blank.setItemMeta(blankIM);

        for (int i = 0; i < inv.getSize(); i++)
            inv.setItem(i, blank);

        Map exit = new HashMap() {{
            put("MATERIAL", Material.BARRIER);
            put("NAME", "§c返回 §f| §c帮助");
            put("LORE", new ArrayList<String>() {{
                add("§b左击§a返回主菜单");
                add("§b右击§a查看帮助");
            }});
            put("LEFT", "/rdp menu");
            put("RIGHT", "/rdp vocation help");
        }};

        inv.setItem(inv.getSize() - 1, RDPUtil.ITEM(exit));
        return inv;
    }
}
